package wg.image.loader
{
	import flash.events.*;
	import flash.display.*;
	import flash.net.URLRequest;
	import flash.display.Sprite;
	
	public class imageLoader extends EventDispatcher {
		
		private var _mc:Sprite;
		
		private var url:String;
		
		private var loader:Loader;
		
		public function imageLoader(_mc:Sprite, url:String) {
			this._mc = _mc;
			this.url = url;
			this.loadImg();
			_mc.addChild(this.loader);
		}
		
		private function loadImg():void {
			this.loader = new Loader();
			this.loader.contentLoaderInfo.addEventListener(Event.COMPLETE, onComplete);
			this.loader.contentLoaderInfo.addEventListener(IOErrorEvent.IO_ERROR, onIOError);
			var request:URLRequest = new URLRequest(url);
			this.loader.load(request);
		}
		
		private function onComplete(event:Event):void {
			dispatchEvent(new Event("onImageLoad"));
		}
		
		private function onIOError(event:IOErrorEvent):void {
			trace("IO Error.");
		}
	
	}
}